import { IBaseTable } from '@feidao/web/atom/nodejs/db/interfaces';
import update from '@feidao/web/atom/nodejs/db/update';
import log from '@feidao/web/atom/nodejs/logger/log';

interface Message {
	systemid: string;
}

interface FruitPrices extends IBaseTable {
	name: string;
	price: number;
}

export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {
	const { systemid } = msg;
	const { exec, prepare } = update(action_id, session_id, spaceid, systemid);
	prepare<FruitPrices>('fruitprices', [{ _id: 'xxx', name: '番茄', price: 5.5 }]);
	const ret = await exec();
	log('result');
	log(JSON.stringify(ret));
	if (ret.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}
